<?php

/**
 * This is the model class for table "web_article_category".
 *
 * The followings are the available columns in table 'web_article_category':
 * @property integer $id
 * @property string $cate_name
 * @property string $cate_enname
 * @property integer $article_count
 */
class ArticleCategory extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ArticleCategory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'web_article_category';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
		array('article_count', 'numerical', 'integerOnly'=>true),
		array('cate_name, cate_enname', 'length', 'max'=>50),
		// The following rule is used by search().
		// Please remove those attributes that should not be searched.
		array('id, cate_name, cate_enname, article_count', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            'arts'=>array(self::HAS_MANY,'Articles','category'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cate_name' => 'Cate Name',
			'cate_enname' => 'Cate Enname',
			'article_count' => 'Article Count',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cate_name',$this->cate_name,true);
		$criteria->compare('cate_enname',$this->cate_enname,true);
		$criteria->compare('article_count',$this->article_count);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}